package leecode.q316;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class Solution {
    Map<Character, List<Integer>> dupMap = new HashMap<>();
    Map<Character, Integer> sinMap = new HashMap<>();

    public String removeDuplicateLetters(String s) {
        int length = s.length();
        sortMap(filter(s.toCharArray()));
        System.out.println(dupMap);
        System.out.println(sinMap);
        String res = findString();
        return "";
    }

    private String findString() {
        char[] chars = new char[dupMap.size() + sinMap.size()];
        System.out.println(chars);
        return "";
    }

    private void sortMap(Map<Character, List<Integer>> map) {
        for (Map.Entry<Character, List<Integer>> entry : map.entrySet()) {
            if (entry.getValue().size() == 1) {
                sinMap.put(entry.getKey(), entry.getValue().get(0));
            } else {
                dupMap.put(entry.getKey(), entry.getValue());
            }
        }
    }

    private Map<Character, List<Integer>> filter(char[] chars) {
        Map<Character, List<Integer>> map = new HashMap<>();
        for (int i = 0; i < chars.length; i++) {
            char c = chars[i];
            if (map.containsKey(c)) {
                map.get(c).add(i);
            } else {
                List<Integer> list = new ArrayList<>();
                list.add(i);
                map.put(c, list);
            }
        }
        return map;
    }
}
